const mongoose = require('./db')


// 登录

const userSchema = new mongoose.Schema({
    username: String,//用户名
    password: String,//密码
    Image: String,//头像
    sex: {
        type: Number,
        default: 0
    }, // 性别 number 0:女 1:男
    age: Number,//年龄
    cardID: Number,//身份证号
    phone: String,//手机号
    address: String,//地址
    relationid: {
        type: mongoose.Types.ObjectId,
        ref: 'relation'
    }//关系id

})

const userModel = mongoose.model('user', userSchema, 'user');

const familySchema = new mongoose.Schema({
    username: String,//用户名
    password: String,//密码
    Image: String,//头像
    sex: {
        type: Number,
        default: 0
    }, // 性别 number 0:女 1:男
    age: Number,//年龄
    cardID: Number,//身份证号
    phone: String,//手机号
    address: String,//地址
    relationid: {
        type: mongoose.Types.ObjectId,
        ref: 'relation'
    },//关系id
    relation: String,//关系
    userid: {
        type: mongoose.Types.ObjectId,
        ref: 'user'
    }//用户id
})
const familyModel = mongoose.model('family', familySchema, 'family');
const RelationSchema = new mongoose.Schema({
    name: String,//类型名称
})
const relationModel = mongoose.model('relation', RelationSchema, 'relation');





// 定义子项的 schema
const ChildItemSchema = new mongoose.Schema({
    text: { type: String, required: true },
});
const ChildItem = mongoose.model('ChildItem', ChildItemSchema);

// 定义主项的 schema，并且允许有 children 字段
const ItemSchema = new mongoose.Schema({
    text: { type: String, required: true },
    children: {
        type: [mongoose.Schema.Types.ObjectId],
        ref: 'ChildItem'
    }
});
const Item = mongoose.model('Item', ItemSchema);

// 评论无限极
const CommentSchema = new mongoose.Schema({
    parentId: String,
    created_at: { type: Date, default: Date.now },
    person: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Person'
    },
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'chatcom'
    },
    content: String,
    likes: String,
    userid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'user'
    },
    level: Number,
    aratar: String,
    name: String,
    likes: Array, //点赞数

})
const chatcomModel = mongoose.model('chatcom', CommentSchema, 'chatcom');


// 院区
const hospitalSchema = new mongoose.Schema({
    name: String, // 工作的院区
    address: String, // 地址
    doctor: {
        type: [mongoose.Schema.Types.ObjectId],
        ref: 'Person'
    }   // 医生
})
const Hospital = mongoose.model('Hospital', hospitalSchema);

// 锦旗
const flagSchema = new mongoose.Schema({
    name: String, // 用户名
    img: {
        type: String,
        default: 'https://cdn7.axureshop.com/demo/2208121/images/%E5%8C%BB%E7%94%9F%E4%B8%BB%E9%A1%B5/u7120.png'
    }, // 锦旗图片
    title: String, // 内容
    date: {
        type: Date,
        default: Date.now
    }, // 日期
})
const Flag = mongoose.model('Flag', flagSchema);


// 医生
const personSchema = new mongoose.Schema({
    name: String, // 添加医生名称字段
    intro: String, // 个人简介
    phone: String,  // 电话
    img: String, // 添加医生头像字段
    job: String, // 添加工作字段
    hospital: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Hospital'
    }, // 添加医院字段
    good: String, // 添加擅长字段
    honor: String,    // 荣誉成就
    item: String, //  主项门诊
    child: String, //  子项科室
    status: {
        type: Boolean,
        default: false
    }, //点赞状态

    visits: {
        type: Number,
        default: 0
    }, // 接诊数
    score: {
        type: Number,
        default: 0
    }, // 患者评分
    comments: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Comment'
    }], // 评论
    flag: {
        type: [mongoose.Schema.Types.ObjectId],
        ref: 'Flag'
    }, // 锦旗数
    followers: Array
})

const Person = mongoose.model('Person', personSchema);

// 范鹏帅
const OutpatientPaymentScheam = new mongoose.Schema({
  hao: String,
  shi: String,
  sheng: String,
  time: String,
  jine: Number,
  flag: Boolean,
});

const OutpatientPayment = mongoose.model("OutpatientPayment", OutpatientPaymentScheam,"OutpatientPayment");



const AdmissRegisterSchema = new mongoose.Schema({
    age: Number, //年龄
    card: String, //就诊卡号
    contactName:String, //联系人姓名
    contactPhone:Number, //联系人联系电话
    curAddress:String, //当前所在地
    curAddressDetails:String, //详细地址
    datePicker:String, //出生日期
    id: String, //身份证号
    nationality1:String,//国籍
    nationality2:String,//民族
    radio:Number,//性别
    username:String,//姓名
    validator2:Number,//手机号
    status:{
        type:Boolean,
        default:false
    }
})
const admissRegisterModel = mongoose.model('admissRegister', AdmissRegisterSchema, 'admissRegister');


const AddCaregiverSchema = new mongoose.Schema({
    // 住院号
    adNumber:String,
    // 患者名称
    username:String,
    // 住院病区
    curAddress:String,
    // 住院床号
    bed:String,
    checked:Number,
    contactPhone:Number,
    name:String,
    id:Number,
    status:{
        type:Boolean,
        default:false
    },
    time:{
        type:Date,
        default:Date.now
    }
})

const addCaregiverModel = mongoose.model('addCaregiver', AddCaregiverSchema, 'addCaregiver');

const CopySchema = new mongoose.Schema({
    username:String,
    card:Number,
    admissNumber:Number,
    phone:Number,
    address:String,
    list:Array,
    name:String,
    time:{
        type:Date,
        default:Date.now
    },
    status:{
        type:Number,
        default:1
    },
    num:Number,
    reason:String

})

const copyModel = mongoose.model('copy', CopySchema, 'copy');

module.exports = {
    admissRegisterModel,
    addCaregiverModel,
    copyModel,
    // 翟一 胡紫藤
    userModel,
    relationModel,
    familyModel,
    // 赵子航
    ChildItem,
    Item,
    chatcomModel,
    Hospital,
    Flag,
    Person,

    // 范鹏帅
    OutpatientPayment



}


